#include <gtest\gtest.h>
#include <Zaf\IniFile.h>
#include <Windows.h>



class IniFile : public testing::Test {

public:
	IniFile() : m_file(L"TestIniFile.ini") {

	}

protected:
	Zaf::IniFile m_file;
};



TEST_F(IniFile, ReadInt) {

	int value = m_file.ReadInt(L"Section", L"KeyInt");
	ASSERT_EQ(333, value);

	value = m_file.ReadInt(L"Section", L"KeyEmpty");
	ASSERT_EQ(0, value);

	value = m_file.ReadInt(L"Section", L"KeyNonexist");
	ASSERT_EQ(0, value);

	value = m_file.ReadInt(L"SectionNonexist", L"KeyInt");
	ASSERT_EQ(0, value);
}



TEST_F(IniFile, ReadString) {

	std::wstring value = m_file.ReadString(L"Section", L"KeyString");
	ASSERT_EQ(L"Zplutor", value);

	value = m_file.ReadString(L"Section", L"KeyEmpty");
	ASSERT_EQ(L"", value);

	value = m_file.ReadString(L"Section", L"KeyNonexist");
	ASSERT_EQ(L"", value);

	value = m_file.ReadString(L"SectionNonexist", L"KeyString");
	ASSERT_EQ(L"", value);

	value = m_file.ReadString(L"Section", L"KeyString32");
	ASSERT_EQ(std::wstring(32, L'a'), value);

	value = m_file.ReadString(L"Section", L"KeyStringMore");
	ASSERT_EQ(std::wstring(34, L'a'), value);
}



TEST_F(IniFile, WriteInt) {

	m_file.WriteInt(L"TestWrite", L"Int", 34);

	wchar_t pathBuffer[MAX_PATH];
	GetFullPathName(L"TestIniFile.ini", MAX_PATH, pathBuffer, nullptr);

	int value = GetPrivateProfileInt(L"TestWrite", L"Int", 0, pathBuffer);
	ASSERT_EQ(34, value);
}


TEST_F(IniFile, WriteString) {

	m_file.WriteString(L"TestWrite", L"String", L"Jneptuner");

	wchar_t pathBuffer[MAX_PATH];
	GetFullPathName(L"TestIniFile.ini", MAX_PATH, pathBuffer, nullptr);

	wchar_t strBuffer[32];
	GetPrivateProfileString(L"TestWrite", L"String", L"", strBuffer, sizeof(strBuffer) / sizeof(wchar_t), pathBuffer);

	ASSERT_STREQ(L"Jneptuner", strBuffer);
}